home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / PowerMacOberon feb96 / Source / HandlerElems.Mod (.txt) < prev    next >
Oberon Text  |  1994-11-24  |  3KB  |  92 lines

  1. Syntax10.Scn.Fnt
  2. StampElems
  3. Alloc
  4. 24 Nov 94
  5. Syntax10b.Scn.Fnt
  6. Syntax10i.Scn.Fnt
  7. MODULE HandlerElems; (* HM 13 Oct 94 / 
  8. IMPORT Display, Viewers, Texts, TextFrames, Oberon, PopupElems;
  9.     Elem* = POINTER TO ElemDesc;
  10.     ElemDesc* = RECORD (PopupElems.ElemDesc) END;
  11.     handle: ARRAY 8 OF Display.Handler; (*handle[cur] is installed in all frames whose menu contains Elem*)
  12.     hName: ARRAY 8, 32 OF CHAR; (*handler names*)
  13.     cur: INTEGER;
  14.     w: Texts.Writer;
  15. PROCEDURE UpdateFrames;
  16.     VAR x: INTEGER; v: Viewers.Viewer; r: Texts.Reader;
  17. BEGIN
  18.     x := 0;
  19.     WHILE x < Display.Width DO
  20.         v := Viewers.This(x, 0);
  21.         WHILE v.state > 1 DO
  22.             IF (v.dsc # NIL) & (v.dsc IS TextFrames.Frame) THEN
  23.                 Texts.OpenReader(r, v.dsc(TextFrames.Frame).text, 0);
  24.                 REPEAT Texts.ReadElem(r) UNTIL r.eot OR (r.elem IS Elem);
  25.                 IF ~r.eot & (v.dsc.next # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  26.                     v.dsc.next.handle := handle[cur]
  27.                 END
  28.             END;
  29.             v := Viewers.Next(v)
  30.         END;
  31.         x := x + v.W
  32. END UpdateFrames;
  33. PROCEDURE SetHandler* (name: ARRAY OF CHAR; new: Display.Handler; VAR old: Display.Handler);
  34.     VAR i: INTEGER;
  35. BEGIN
  36.     i := 0;
  37.     WHILE (i <= cur) & (handle[i] # new) DO INC(i) END;
  38.     IF i > cur THEN
  39.         old := handle[cur]; INC(cur); handle[cur] := new; COPY(name, hName[cur])
  40.     ELSIF i > 0 THEN cur := i; old := handle[cur-1]
  41.     ELSE cur := 0; old := TextFrames.Handle
  42.     END;
  43.     UpdateFrames
  44. END SetHandler;
  45. PROCEDURE ResetHandlers*;
  46. BEGIN
  47.     handle[0] := TextFrames.Handle; hName[0] := "TextFrames.Handle"; cur := 0; UpdateFrames
  48. END ResetHandlers;
  49. PROCEDURE ListHandlers*;
  50.     VAR i: INTEGER;
  51. BEGIN
  52.     FOR i := 0 TO cur DO
  53.         Texts.WriteString(w, hName[i]); Texts.WriteLn(w)
  54.     END;
  55.     Texts.Append(Oberon.Log, w.buf)
  56. END ListHandlers;
  57. PROCEDURE Handle* (e: Texts.Elem; VAR m: Texts.ElemMsg);
  58.     VAR e1: Elem; f: Display.Frame;
  59. BEGIN
  60.     WITH m: Texts.CopyMsg DO
  61.         IF m.e = NIL THEN NEW(e1); m.e := e1 END;
  62.         PopupElems.Handle(e, m)
  63.     | m: Texts.IdentifyMsg DO
  64.         m.mod := "HandlerElems"; m.proc := "Alloc"
  65.     | m: TextFrames.DisplayMsg DO
  66.         PopupElems.Handle(e, m);
  67.         IF ~m.prepare THEN 
  68.             f := m.frame.next;
  69.             IF (f # NIL) & (f IS TextFrames.Frame) & (f(TextFrames.Frame).handle # handle[cur]) THEN
  70.                 f(TextFrames.Frame).handle := handle[cur]
  71.             END
  72.         END
  73.     ELSE PopupElems.Handle(e, m)
  74. END Handle;
  75. PROCEDURE Alloc*;
  76.     VAR e: Elem;
  77. BEGIN
  78.     NEW(e); e.handle := Handle; Texts.new := e
  79. END Alloc;
  80. PROCEDURE Insert*;
  81.     VAR e: Elem; insert: TextFrames.InsertElemMsg;
  82. BEGIN
  83.     NEW(e); e.handle := Handle; e.name := "H"; e.small := TRUE;
  84.     e.menu := TextFrames.Text("");
  85.     Texts.WriteString(w, "This is a HandlerElems.Elem"); Texts.Append(e.menu, w.buf);
  86.     PopupElems.MeasureMenu(e);
  87.     insert.e := e; Viewers.Broadcast(insert)
  88. END Insert;
  89. BEGIN
  90.     ResetHandlers; Texts.OpenWriter(w)
  91. END HandlerElems.
  92.